﻿using System;
using System.Collections.Generic;
using System.Text;
using Hkwl.WorldExpo.Merchant.Model;
using System.Collections;

namespace Hkwl.WorldExpo.Merchant.DataAccess.Impl.IBatisNet
{
    public class ClientSqlMapDao : BaseSqlMapDao, IClientDao
    {

        #region NxClient 对象

        public NxClient GetNxClientById(int clientId)
        {
            return ExecuteQueryForObject<NxClient>("SelectNxClient", clientId);
        }

        public bool InsertNxClient(NxClient client)
        {
            object obj = ExecuteInsert("InsertNxClient", client);
            if ((int)obj > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public bool UpdateNxClient(NxClient client)
        {
            int ret = ExecuteUpdate("UpdateNxClient", client);
            if (ret > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public bool DeleteNxClient(int clientId)
        {
            Hashtable ht = new Hashtable();
            ht["ClientId"] = clientId;

            int ret = ExecuteDelete("DeleteNxClient", ht);
            if (ret > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public int GetNxClientByCellphone(string cellphone, int merchantId)
        {
            Hashtable ht = new Hashtable();
            ht["CellPhone"] = cellphone;
            ht["MerchantId"] = merchantId;
            return ExecuteQueryForObject<int>("GetNxClientCountByCellphone", ht);
        }

        public IList<NxClient> GetNxClientCollection(int merchantId, int pageIndex, int pageSize, ref int count)
        {
            Hashtable ht = new Hashtable();
            ht["MerchantId"] = merchantId;
            count = ExecuteQueryForObject<int>("GetNxClientCollectionCount", ht);
            return ExecuteQueryForList<NxClient>("GetNxClientCollection", ht, (pageIndex - 1) * pageSize, pageSize);
        }

        public IList<NxClient> GetNxClientNotInGroup(int groupId,int merchantId)
        {
            Hashtable ht = new Hashtable();
            ht["GroupId"] = groupId;
            ht["MerchantId"] = merchantId;
            return ExecuteQueryForList<NxClient>("SelectNxClientNotInGroup", ht);
        }

        public IList<NxClient> GetNxClientInGroup(int groupId, int merchantId)
        {
            Hashtable ht = new Hashtable();
            ht["GroupId"] = groupId;
            ht["MerchantId"] = merchantId;
            return ExecuteQueryForList<NxClient>("SelectNxClientInGroup", ht);
        }

        #endregion

        #region NxGroup 对象

        public bool InsertNxGroup(NxGroup group)
        {
            object obj = ExecuteInsert("InsertNxGroup", group);
            if ((int)obj > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public bool DeleteNxGroup(int groupId)
        {
            Hashtable ht = new Hashtable();
            ht["GroupId"] = groupId;

            int ret = ExecuteDelete("DeleteNxGroup", ht);
            if (ret > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public IList<NxGroup> GetNxGroupCollection(int merchantId)
        {
            return ExecuteQueryForList<NxGroup>("SelectNxGroupByMerchantId", merchantId);
        }

        public bool UpdateNxGroup(NxGroup group)
        {
            int ret = ExecuteUpdate("UpdateNxGroup", group);
            if (ret > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public NxGroup GetNxGroupById(int groupId)
        {
            return ExecuteQueryForObject<NxGroup>("SelectNxGroup", groupId);
        }

        public int GetNxGroupCountByName(string groupName, int merchantId)
        {
            Hashtable ht = new Hashtable();
            ht["GroupName"] = groupName;
            ht["MerchantId"] = merchantId;
            return ExecuteQueryForObject<int>("GetNxGroupCountByName", ht);
        }

        #endregion

        #region NxGroupClient 对象

        public bool InsertNxGroupClient(NxGroupClient groupClient)
        {
            object obj = ExecuteInsert("InsertNxGroupClient", groupClient);
            if ((int)obj > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public IList<NxGroupClient> GetNxGroupClientCollection(int groupId, int pageIndex, int pageSize, ref int count)
        {
            Hashtable ht = new Hashtable();
            ht["GroupId"] = groupId;

            count = ExecuteQueryForObject<int>("GetNxGroupClientCollectionCount", ht);
            return ExecuteQueryForList<NxGroupClient>("GetNxGroupClientCollection", ht, (pageIndex - 1) * pageSize, pageSize);
        }

        public bool DeleteNxGroupClient(int groupId, int clientId)
        {
            Hashtable ht = new Hashtable();
            ht["GroupId"] = groupId;
            ht["ClientId"] = clientId;

            int ret = ExecuteDelete("DeleteNxGroupClient", ht);
            if (ret > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public bool DeleteNxGroupClientByGroup(int groupId)
        {
            Hashtable ht = new Hashtable();
            ht["GroupId"] = groupId;

            int ret = ExecuteDelete("DeleteNxGroupClientByGroup", ht);
            if (ret > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        #endregion
    }
}
